<?php
/**
 * Action to reset a user's password		Registed as 'action/user/password/reset'
 *  
 * $email
 * $pass
 */

#################################################################
#								ACTION
#################################################################
if($_CONTEXT==CONTEXT_ACTION){

	$email= blg_get_input('email');
	
	if(!v_is_email($email)){
		blg_msg_add(blg_echo('error:email:invalid'), true);
		forward(blg_get_site_url().'user/password/forgotten?'.blg_security_url());
	}
	
	if(blg_email_exists($email)){
		$user= blg_get_user_entity_by_email($email);
		
		//NOT ACTIVE
		if($user->is_not_active()){
			blg_user_send_validation_email($user->guid);
			blg_msg_add(blg_echo('register:confirm:not', array($user->email)), true);
			blg_msg_add(blg_echo('register:valdiate:str1', array($user->email)), false);
			blg_msg_add(blg_echo('register:confirm2', array($user->email)), false);				
			forward();			
		}
		
		//SEND RESET EMAIL
		blg_user_send_confirm_reset_password_email($user->guid);
		blg_msg_add(blg_echo('forms:password:reset:email:sent:1'));
		blg_msg_add(blg_echo('forms:password:reset:email:sent:2', array($user->email)), false);
		blg_msg_add(blg_echo('email:in:spam'));		
		forward();		
	}	
	
	//Try again
	blg_msg_add(blg_echo('forms:password:reset:email:no', array($email)), true);
	forward(blg_get_site_url().'user/password/forgotten?'.blg_security_url());
	
}
#################################################################
#								ACCESS
#################################################################
elseif($_CONTEXT==CONTEXT_ACCESS){ 
	$_ACCESS= (blg_user_is_logged_in()===FALSE && blg_security_grant_from_input());
}
